#!usr/bin/env python
#-*- coding:utf-8 _*-
"""
@author:vonzhe
@file: experimentData_loader.py
"""
import pandas as pd
import numpy as np



class CrossBarLoader(object):

	def __init__(self, setPath, resetPath):
		self.setPath = setPath
		self.resetPath = resetPath

	def getGInfo(self,readVoltage=0.01):
		set_data = pd.read_csv(self.setPath).values
		setG_data = set_data / readVoltage  # Conductance Value
		setG_mean = np.mean(setG_data, axis=1)
		setG_mean = np.sort(setG_mean)
		# std = np.std(data, axis=1)
		G_max1 = np.max(setG_mean)
		G_min1 = np.min(setG_mean)

		reset_data = pd.read_csv(self.resetPath).values
		resetG_data = reset_data / readVoltage  # Conductance Value
		resetG_mean = np.mean(resetG_data, axis=1)
		resetG_mean = np.sort(resetG_mean)[::-1]
		# std = np.std(data, axis=1)
		G_max2 = np.max(resetG_mean)
		G_min2 = np.min(resetG_mean)

		G_max = min(G_max1, G_max2)
		G_min = max(G_min1, G_min2)
		G_mean = (G_max+G_min)*0.5
		return G_max, G_min, G_mean, setG_mean, resetG_mean








if __name__ == '__main__':
	set_path = r"E:\References\Crosssim\examples\lookup_table_example\set.csv"
	reset_path = r"E:\References\Crosssim\examples\lookup_table_example\reset.csv"
	crossbar = CrossBarLoader(set_path,reset_path)
	G_max, G_min, G_mean, setG_mean, resetG_mean = crossbar.getGInfo()

	print(setG_mean.size,'\n',setG_mean)
	print("----------------------------------------------")
	print(resetG_mean.size, '\n', resetG_mean)

